package org.example.jedis;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * @author 宋孟林
 * @description 学习推荐redis与java程序的客户端jedis
 * @create: 2025/3/7 15:23
 */
public class JedisDemo {
    public static void main(String[] args) {
        //1.通过ip和端口来连接服务器
        Jedis jedis = new Jedis("192.168.100.133", 6379);
        //2.指定redis服务器的密码
        jedis.auth("123456");
        //3.获得了jedis客户端，就可以像jdbc一样访问redis数据库了。
        System.out.println(jedis.ping());
        Set<String> keys = jedis.keys("*");
        System.out.println(keys);
        jedis.set("h3", "hello,jedis");
        String hello = jedis.get("hello");
        String h3 = jedis.get("h3");
        System.out.println("hello = " + hello);
        System.out.println("h3 = " + h3);
        System.out.println(jedis.getConnection());
        Set<String> keys1 = jedis.keys("*");
        System.out.println(keys1);
        System.out.println("=====================");
        System.out.println("Current DB: " + jedis.info("keyspace"));
        jedis.close();
    }
}
